﻿using System.Collections.Generic;
using MvcContrib.Shp.UI.Themed.Grid;
using Shp.Web.Models.Domain;
using MvcContrib.UI.Grid;
using MvcContrib.UI.Grid.Syntax;

namespace Shp.Web.Models.GridModels
{
    public class CustomerGridModel : GridModel<Customer>
    {
        public CustomerGridModel()
        {
            Column.For(x => x.FirstName);
            Column.For(x => x.LastName);
            Column.For(x => x.Company);
            Column.For(x => x.Address);
            Column.Custom(x => GetCityLink(x.City)).Named("City").SortColumnName("City");
            Column.For(x => x.State);
            Column.For(x => x.Country);
            Column.For(x => x.PostalCode);
            Column.For(x => x.Phone);
            //Column.For(x => x.Fax);
            Column.For(x => x.Email);
            //Column.For(x => x.SupportRepresentative).Named("Support Rep");

            RenderUsing(new HtmlTableGridThemedRenderer<Customer>());
        }

        private static string GetCityLink(string city)
        {
            return string.IsNullOrWhiteSpace(city)
                       ? string.Empty
                       : string.Format("<a href=\"http://www.bing.com/search?q={0}\" target=\"_blank\">{0}</a>", city);
        }
    }
}